
// 缓存相关
export const GT = key => window.sessionStorage.getItem(key)
export const ST = (key, value) => window.sessionStorage.setItem(key, value)

export const GT_A = (key, type = '[]') => JSON.parse(GT(key) || type)
export const ST_A = (key, value) => ST(key, JSON.stringify(value))

// location
export const getLocation = () => window.location

// 获取查询参数
export const getQuery = value => value ? value.split('&').map(item => item.split('=')).reduce((a, b) => b[1] ? (a[b[0]] = b[1]) && a : (a[b[0]] = b[1]) || a, {}) : {}


// 获取页面数据
let pageDetailOrigin = ''
let pageDetailSearch = ''
export const getPageDetail = url => url ? {
	href: url,
	origin: (pageDetailOrigin = url.match(/^https?\:\/\/[^\/]+/)[0]),
	pathname: url.split(pageDetailOrigin)[1].match(/^[^?]*/)[0],
	query: getQuery(pageDetailSearch = url.split('?')[1]),
	search: pageDetailSearch ? `?${pageDetailSearch}` : ''
} : {}


// 获取当前时间戳
export const getNowDate = () => Date.now ? Date.now() : new Date().getTime()